package com.bigdata.bookinfo.mapper;

import com.bigdata.bookinfo.pojo.Book;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class BookMapper extends Mapper<LongWritable, Text, Text, Book> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String str = new String(value.getBytes(),0,value.getLength(),"GBK");
        String[] line = str.split(",");
        if (line.length!=10){
            return;
        }
        String title = line[0].replace("?","·").replace(" ","，");
        String comment = line[1];
        String recommend = line[2];
        String author = line[3].replace("?","·");
        String date = line[4];
        String press = line[5];
        String price_n = line[6];
        String price_r = line[7];
        String price_s = line[8];
        String href = line[9];
        Book book = new Book(title,comment,recommend,author,date,press,price_n,price_r,price_s,href);
        context.write(new Text(title),book);
    }

}
